/**
 * Copyright (C) 2008-2009 Cristian Olaru <colaru@gmail.com>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *         http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.integrationpath.mengine.webapp.decorator;

import org.displaytag.decorator.TableDecorator;
import com.integrationpath.mengine.model.Article;
import com.integrationpath.mengine.webapp.listener.StartupListener;
import com.integrationpath.mengine.webapp.util.EngineConstants;

public class ArticleDecorator extends TableDecorator {

	String response = "";
	Article message;
	
	public ArticleDecorator() {		
	}

	
	public String getState() {
		Article article = (Article)getCurrentRowObject();
		int newStatus =  1-article.getStatus().intValue();
		switch (article.getStatus()) {
		case EngineConstants.ARTICLE_ENABLED:
			response = "<img title='ENABLED' alt='ENABLED' src='" + StartupListener.getAppContext().getAttribute("path_theme") + "/images/available.png'/>";
			break;
		case EngineConstants.ARTICLE_DISABLED:
			response = "<img title='DISABLED' alt='DISABLED' src='" + StartupListener.getAppContext().getAttribute("path_theme") + "/images/unavailable.png'/>";
			break;
		}	
		return response;
	}
	
	public String getPreview() {
		Article article = (Article)getCurrentRowObject();
		int newStatus =  1-article.getStatus().intValue();
		response = "<a target='_blank' href='content_" + article.getTitleLine() + "_" + article.getId() + "'><img title='PREVIEW' src='" + StartupListener.getAppContext().getAttribute("path_theme") + "/images/article-preview.png'/></a>";
		return response;
	}
	
	public String getAdminState() {
		Article article = (Article)getCurrentRowObject();
		int newStatus =  1-article.getStatus().intValue();
		switch (article.getStatus()) {
		case EngineConstants.ARTICLE_ENABLED:
			response = "<a id='image" + article.getId() + "' onclick='changeArticleStatusCode(" + article.getId() + "," + article.getStatus() + ")'><img alt='ENABLED' src='" + StartupListener.getAppContext().getAttribute("path_theme") + "/images/available.png'/><a/>";
			break;
		case EngineConstants.ARTICLE_DISABLED:
			response = "<a id='image" + article.getId() + "' onclick='changeArticleStatusCode(" + article.getId() + "," + article.getStatus() +  ")'><img alt='DISABLED' src='" + StartupListener.getAppContext().getAttribute("path_theme") + "/images/unavailable.png'/><a/>";
			break;
		}	
		return response;
	}
	
	public String getAdminFeatured() {
		Article article = (Article)getCurrentRowObject();
		int newFeatured =  1-article.getFeatured().intValue();
		switch (article.getFeatured()) {
		case EngineConstants.ARTICLE_FEATURED:
			response = "<a id='image" + article.getId() + "' onclick='changeArticleFeaturedCode(" + article.getId() + "," + article.getFeatured() + ")'><img alt='FEATURED' src='" + StartupListener.getAppContext().getAttribute("path_theme") + "/images/featured.png'/><a/>";
			break;
		case EngineConstants.ARTICLE_UNFEATURED:
			response = "<a id='image" + article.getId() + "' onclick='changeArticleFeaturedCode(" + article.getId() + "," + article.getFeatured() +  ")'><img alt='UNFEATURED' src='" + StartupListener.getAppContext().getAttribute("path_theme") + "/images/unfeatured.png'/><a/>";
			break;
		}	
		return response;
	}
}
